#pragma once
#include <map>
#include <fstream>
#include <iostream>

using namespace std;

namespace U33
{
	class CalcWords
	{
	private:
		map<string, int> ma;
	public:

		CalcWords()
		{
		}

		~CalcWords()
		{
		}

		void readFromFile()
		{
			ifstream fin;
			fin.open("nils_holgersson.txt");
			string s;
			while (fin.good())
			{
				fin >> s;
				for (auto &m : ma)
				{
					if (!m.first.compare(s))
					{
						m.second++;
					}
				}
				ma.insert(std::pair<string, int>(s, 1));
			}
		}

		int findMax(string &ord)
		{
			int max = 0;
			string word;
			for (auto &m : ma)
			{
				if (m.second > max)
				{
					max = m.second;
					ord = m.first;
				}
			}
			return max;
		}

	};
}

